﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Data.Services.Client;
using System.Windows.Forms;

namespace ODataSource
{
    internal class EntitySetPropertyEditor: StringConverter
    {
        public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
        {
            return true;
        }

        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            var list = new List<string>();

            try
            {
                var datasource = context.Instance as ODataSource;

                if (datasource.ContextTypeName != null)
                {
                    var cx = Type.GetType(datasource.ContextTypeName);
                    if (cx != null)
                        list.AddRange(from p in cx.GetProperties()
                                      where p.PropertyType.IsSubclassOf(typeof(DataServiceQuery))
                                      select p.Name);
                }

            }
            catch
            { 

            } 
            return new StandardValuesCollection(list);                    
        }
    }
}
